home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / System 7.0 Samples / Kibitz⁄THINK C / Utils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-21  |  4.2 KB  |  229 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** Program:     Kibitz
  5. ** File:        utils.c
  6. ** Written by:  Eric Soldan
  7. **
  8. ** Copyright © 1990-1991 Apple Computer, Inc.
  9. ** All rights reserved.
  10. */
  11.  
  12.  
  13.  
  14. /*****************************************************************************/
  15.  
  16.  
  17.  
  18. #include "Kibitz.h"                /* Get the Kibitz includes/typedefs, etc.    */
  19. #include "KibitzCommon.h"        /* Get the stuff in common with rez.        */
  20. #include "Kibitz.protos"        /* Get the prototypes for Kibitz.            */
  21.  
  22. #ifndef __STRING__
  23. #include <String.h>
  24. #endif
  25.  
  26. #ifndef __UTILITIES__
  27. #include "Utilities.h"
  28. #endif
  29.  
  30.  
  31.  
  32. #define BASE 10
  33.  
  34.  
  35.  
  36. /*****************************************************************************/
  37.  
  38.  
  39.  
  40. #pragma segment Main
  41. void    appendi2cstr(char *cstr, short i)
  42. {
  43.     i2cstr(cstr + strlen(cstr), i);
  44. }
  45.  
  46.  
  47.  
  48. /*****************************************************************************/
  49.  
  50.  
  51.  
  52. #pragma segment Main
  53. short    appendi2pstr(char *pstr, short i)
  54. {
  55.     short    j;
  56.  
  57.     j = 0;
  58.     if (i >= BASE) j = appendi2pstr(pstr, i / BASE);
  59.     pstr[++*pstr] = "0123456789ABCDEF"[i - j];
  60.     return(BASE * i);
  61. }
  62.  
  63.  
  64.  
  65. /*****************************************************************************/
  66.  
  67.  
  68.  
  69. #pragma segment Main
  70. short    i2cstr(char *cstr, short i)
  71. {
  72.     short    j;
  73.  
  74.     cstr[1] = j = 0;
  75.     if (i >= BASE)
  76.         j = i2cstr(cstr + 1, i / BASE);
  77.     *cstr = "0123456789ABCDEF"[i - j];
  78.     return(BASE * i);
  79. }
  80.  
  81.  
  82.  
  83. /*****************************************************************************/
  84.  
  85.  
  86.  
  87. #pragma segment Main
  88. void    i2pstr(char *pstr, short i)
  89. {
  90.     *pstr = 0;
  91.     appendi2pstr(pstr, i);
  92. }
  93.  
  94.  
  95.  
  96. /*****************************************************************************/
  97.  
  98.  
  99.  
  100. #pragma segment Main
  101. void    pstrcat(char *d, char *s)
  102. {
  103.     short    i;
  104.  
  105.     for (i = 0; i < s[0];)
  106.         d[++d[0]] = s[++i];
  107. }
  108.  
  109.  
  110.  
  111. /*****************************************************************************/
  112.  
  113.  
  114.  
  115. #pragma segment Main
  116. void    pstrcpy(char *d, char *s)
  117. {
  118.     short    i;
  119.  
  120.     i = *s;
  121.     do {
  122.         d[i] = s[i];
  123.     } while (i--);
  124. }
  125.  
  126.  
  127.  
  128. /*****************************************************************************/
  129.  
  130.  
  131.  
  132. #pragma segment Main
  133. short    GetHexByte(char *cptr)
  134. {
  135.     short    val, i, chr;
  136.  
  137.     for (val = 0, i = 0; i < 2; ++i) {
  138.         chr = cptr[i];
  139.         if (chr == '=') return(cptr[++i]);
  140.         if (chr > 'F') chr -= 0x20;
  141.         if (chr > '9') chr -= ('A' - '9' - 1);
  142.         val = (val << 4) + chr - '0';
  143.     }
  144.     return(val);
  145. }
  146.  
  147.  
  148.  
  149. /*****************************************************************************/
  150.  
  151.  
  152.  
  153. /* This code expects the key equivalents to be in item #2, which is a StatText
  154. ** item that is located so the text is outside of the dialog.  This allows us
  155. ** to put key equivalent information in the resource fork, so the key
  156. ** equivalents are localizable. */
  157.  
  158. #pragma segment Main
  159. pascal Boolean    keyEquivFilter(DialogPtr dlg, EventRecord *event, short *item)
  160. {
  161.     short    itemType;
  162.     Handle    itemHndl;
  163.     Rect    itemRect;
  164.     Str255    itemText;
  165.     short    i, theChr, theMod, equivChr, modMask, modVal, itemNum;
  166.     long    tick;
  167.  
  168.     if (event->what == updateEvt) {
  169.         if (dlg == (DialogPtr)event->message) OutlineDialogItem(dlg, 1);
  170.         return(false);
  171.     }
  172.  
  173.     if (event->what != keyDown) return(false);
  174.  
  175.     itemNum = 0;
  176.  
  177.     theChr = event->message   & charCodeMask;
  178.     theMod = event->modifiers & keyCodeMask;
  179.  
  180.     if ((theChr == 0x0D) || (theChr == 0x03)) {        /* If return or enter... */
  181.         if (!(theMod & (cmdKey + optionKey + controlKey))) itemNum = 1;
  182.     }        
  183.     else {
  184.  
  185.         GetDItem(dlg, 2, &itemType, &itemHndl, &itemRect);
  186.         GetIText(itemHndl, itemText);
  187.  
  188.         for (i = 1; i <= *itemText; i += 9) {
  189.             equivChr = GetHexByte((char *) itemText + i);
  190.             modMask  = GetHexByte((char *) itemText + i + 2) << 8;
  191.             modVal   = GetHexByte((char *) itemText + i + 4) << 8;
  192.             itemNum  = GetHexByte((char *) itemText + i + 6);
  193.             if (theChr == equivChr)
  194.                 if ((theMod & modMask) == modVal) break;
  195.             itemNum = 0;
  196.         }
  197.     }
  198.  
  199.     if (itemNum) {
  200.         GetDItem(dlg, itemNum, &itemType, &itemHndl, &itemRect);
  201.         HiliteControl((ControlHandle)itemHndl, 1);
  202.         tick = TickCount();
  203.         while (TickCount() < tick + 10);
  204.         HiliteControl((ControlHandle)itemHndl, 0);
  205.         *item = itemNum;
  206.         return(true);
  207.     }
  208.  
  209.     return(false);
  210. }
  211.  
  212.  
  213.  
  214. /*****************************************************************************/
  215.  
  216.  
  217.  
  218. #pragma segment Main
  219. void    OffsetControl(ControlHandle ctl, short dx, short dy)
  220. {
  221.     Rect    ctlRect;
  222.  
  223.     ctlRect = (*ctl)->contrlRect;
  224.     MoveControl(ctl, ctlRect.left + dx, ctlRect.top + dy);
  225. }
  226.  
  227.  
  228.  
  229.